<?php
/* @var $this UserController */
/* @var $model User */
/* @var $form CActiveForm */
?>

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'edit-form',
	'htmlOptions'=> array('class'=>'form-horizontal')
)); ?>

	<?php echo $form->errorSummary($model); ?>

	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span6">
				<?php echo $this->renderPartial('form/col1', array(
					'form'=>$form,
					'model'=>$model
				)); ?>
			</div>
			
			<div class="span6">
				<?php echo $this->renderPartial('form/col2', array(
					'form'=>$form,
					'model'=>$model
				)); ?>
			</div>
		</div>
		<div class="row-fluid">
			<div class="control-group">
				<label class="control-label"><?php echo Yii::t('app', 'Profile pictures') ?></label>
				<div class="controls">
					<p><em><?php echo Yii::t('app', 'Select picture to remove') ?></em></p>
					
					<?php foreach($model->images as $img):?>
					<div class="imgobj">
						<div class="imgframe">
							<img src="<?php echo $img->getImageUrl() ?>" alt="<?php echo $img->file ?>" />
						</div>
						<div class="actions">
							<input type="checkbox" name="remove_images[]" value="<?php echo $img->id ?>"/>
							<a href="<?php echo $this->createUrl('deleteImage',array('id'=>$img->id)) ?>" class="btn btn-danger btnDelete"><?php echo Yii::t('app', 'Delete' ) ?></a>
						</div>
					</div>
					<?php endforeach ?>
				</div>
			</div>
		</div>
	</div>
<?php $this->endWidget(); ?>

<script>
//<![CDATA[
function setImgVertialAlign() {
	$('.imgframe img').each(function () {
		var h1 = $(this).parent().height();
		var h2 = $(this).height();
		var mt = h2<h1 ? (h1-h2)/2 : 0;
		$(this).css('margin-top', mt+'px');
	});
}

$(window).load(function () {
	setImgVertialAlign();
	$('.btnDelete').click(function (e) {
		if(confirm("<?php echo Yii::t('app', 'Are you sure you want to delete this item') ?>?")) {
			$('body > .main').addClass('loading');
			
			$.ajax({
			type: 'POST',
			url: this.href,
			success: function (data) {
				location.reload(); 			
			},
			error: function (XHR, textStatus, errorThrown) { }
		});
		}
		e.preventDefault();
	});
});
//]]>
</script>